﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Project.MODEL;
using Project.BLL.System;

namespace Project.UI.Areas.System.Controllers
{
    public class OrganizationController : Controller
    {
        OrganizationBll bll = new OrganizationBll();

        // Organization 视图
        public ActionResult Organization()
        {
            return View();
        }

        // View 视图
        [CheckLogin]
        public ActionResult Roles(int id)
        {
            ViewBag.roleID = id;
            ViewBag.roleName = Request.QueryString["rname"];
            ViewBag.deptName = Request.QueryString["dname"];
            return View();
        }

        public ActionResult GetDepartmentAll()
        {
            var list = bll.GetDepartmentAll();
            return Content(list, "Application/Json");
        }

        public ActionResult GetRolesAll()
        {
            var list = bll.GetRolesAll();
            return Content(list, "Application/Json");
        }

        public ActionResult GetOrganization() {
            var list = bll.GetOrganization();
            return Content(list, "Application/Json");
        }

        [HttpPost]
        public ActionResult AddDepartment(Department dept)
        {
            dept.lastTime = DateTime.Now;
            return Content(bll.AddDepartment(dept), "Application/Json");
        }

        [HttpPost]
        public ActionResult UpdateDepartment(Department dept)
        {
            dept.lastTime = DateTime.Now;
            return Content(bll.UpdateDepartment(dept), "Application/Json");
        }

        [HttpPost]
        public ActionResult DeleteDepartment(int id)
        {
            return Content(bll.DeleteDepartmentByID(id), "Application/Json");
        }

        [HttpPost]
        public ActionResult AddRoles(Roles role)
        {
            role.lastTime = DateTime.Now;
            var data = bll.AddRoles(role);
            return Content(data, "Application/Json");
        }

        [HttpPost]
        public ActionResult UpdateRoles(Roles role)
        {
            role.lastTime = DateTime.Now;
            return Content(bll.UpdateRoles(role), "Application/Json");
        }

        [HttpPost]
        public ActionResult DeleteRoles(int id)
        {
            return Content(bll.DeleteRolesByID(id), "Application/Json");
        }


    }
}